package com.kawaiior.asoulworld.entity.creatures.misc;

import com.kawaiior.asoulworld.item.ModItems;
import net.minecraft.entity.IEntityLivingData;
import net.minecraft.entity.SharedMonsterAttributes;
import net.minecraft.entity.monster.EntitySkeleton;
import net.minecraft.init.Items;
import net.minecraft.inventory.EntityEquipmentSlot;
import net.minecraft.item.ItemStack;
import net.minecraft.util.DamageSource;
import net.minecraft.world.DifficultyInstance;
import net.minecraft.world.World;

import javax.annotation.Nullable;

public class EntityBewilderedManPlus extends EntitySkeleton {
    public EntityBewilderedManPlus(World worldIn) {
        super(worldIn);
    }

    protected void applyEntityAttributes()
    {
        super.applyEntityAttributes();
        this.getEntityAttribute(SharedMonsterAttributes.FOLLOW_RANGE).setBaseValue(20.0D);
        this.getEntityAttribute(SharedMonsterAttributes.MOVEMENT_SPEED).setBaseValue(0.2D);
        this.getEntityAttribute(SharedMonsterAttributes.ATTACK_DAMAGE).setBaseValue(3.0D);
        this.getEntityAttribute(SharedMonsterAttributes.ARMOR).setBaseValue(2.0D);
        this.getEntityAttribute(SharedMonsterAttributes.MAX_HEALTH).setBaseValue(40D);
    }

    @Nullable
    public IEntityLivingData onInitialSpawn(DifficultyInstance difficulty, @Nullable IEntityLivingData livingdata)
    {
        livingdata = super.onInitialSpawn(difficulty, livingdata);

        this.setItemStackToSlot(EntityEquipmentSlot.MAINHAND, new ItemStack(Items.IRON_SWORD));
        this.setEnchantmentBasedOnDifficulty(difficulty);
        this.setCanPickUpLoot(true);
        setItemStackToSlot(EntityEquipmentSlot.HEAD, new ItemStack(Items.IRON_HELMET));
        setItemStackToSlot(EntityEquipmentSlot.CHEST, new ItemStack(Items.IRON_CHESTPLATE));
        setItemStackToSlot(EntityEquipmentSlot.LEGS, new ItemStack(Items.LEATHER_LEGGINGS));
        setItemStackToSlot(EntityEquipmentSlot.FEET, new ItemStack(Items.LEATHER_BOOTS));


        return livingdata;
    }

    @Override
    protected void dropLoot(boolean wasRecentlyHit, int lootingModifier, DamageSource source)
    {
        super.dropLoot(wasRecentlyHit,lootingModifier,source);
        if (!world.isRemote)
        {
            if (rand.nextFloat() < 0.3 + 0.05 * lootingModifier)
            {
                dropItem(ModItems.AS_PURE_GOLD,rand.nextInt(4)+1);
            }
            if (rand.nextFloat() < 0.3 + 0.05 * lootingModifier)
            {
                dropItem(ModItems.AS_SOUL_STONE,rand.nextInt(4)+1);
            }
            if (rand.nextFloat() < 0.3 + 0.05 * lootingModifier)
            {
                dropItem(ModItems.DIANA_CANDY,rand.nextInt(4)+1);
            }

        }
    }
}
